package com.coding.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;


/**
 * -- Created by IntelliJ IDEA.
 * -- REMARK:
 * -- User: tanwei
 * -- Date: 2020/7/5
 * -- Time: 9:53 上午
 * --
 */
//swagger配置类
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket docket1(Environment environment) {
        return new Docket(DocumentationType.SWAGGER_2).groupName("groupName1");
    }
    @Bean
    public Docket docket2(Environment environment) {
        return new Docket(DocumentationType.SWAGGER_2).groupName("groupName2");
    }
    @Bean
    public Docket docket3(Environment environment) {
        return new Docket(DocumentationType.SWAGGER_2).groupName("groupName3");
    }
    //注册bean  dcoker
    @Bean
    public Docket docket(Environment environment) {
        Profiles of = Profiles.of("dev", "test");
        boolean b = environment.acceptsProfiles(of);
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("now1")//分组
                .enable(b)
                .apiInfo(apiInfo())//配置文档信息
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.coding.controller"))
                //配置path过滤请求！只扫描以***开头的请求
                .paths(PathSelectors.ant("/***"))
                .build();
    }


    public ApiInfo apiInfo() {
        Contact contact = new Contact("coding", "https:www.baidu.com", "tanw019@163.com");

        return new ApiInfo("SptringBoot接口信息", "所有测试参数", "v1.0", "https:www.baidu.com", contact, "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", new ArrayList<VendorExtension>());

    }


}
